class Solution {
public:
    int GetSum(int n)
    {
        int sum = 0;
        while (n)
        {
            int b = n % 10;
            sum += b * b;
            n /= 10;
        }
        return sum;
    }
    bool isHappy(int n) {
        int slow = n, fast = GetSum(n);
        while (slow != fast)
        {
            slow = GetSum(slow);
            fast = GetSum(fast);
            fast = GetSum(fast);
        }
        return slow == 1;
    }
};